<%--
  Created by IntelliJ IDEA.
  User: 仁
  Date: 2021-03-27
  Time: 12:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>公告</title>
    <base href="<%=request.getContextPath()%>/"/>
    <link rel="stylesheet" href="webjars/layui/2.5.5/css/layui.css">
</head>
<body>
<div class="layui-container">
    <div class="layui-collapse">
        <div class="layui-colla-item">
            <div class="layui-colla-title">查询条件</div>
            <div class="layui-colla-content layui-show">
                <form class="layui-form layui-inline">

                    <div class="layui-inline">
                        <input type="text" class="layui-input" id="drugname" placeholder="根据发布时间进行查询">
                    </div>
                    <div class="layui-input-inline">
                        <button type="button" class="layui-btn" id="chaxun" onclick="search()" data-type="reload">查询</button>
                    </div>
                    <div class="layui-input-inline">
                        <button type="button" class="layui-btn" id="pishan" onclick="delAll()">删除选中行数据</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <table id="roleTb" lay-filter="roleTb"></table>
</div>

<script src="webjars/layui/2.5.5/layui.js"></script>
<script>
    layui.use(['form','table','jquery'], function(){
        let table=layui.table;
        table.render({
            id:"roleTb",
            elem:"#roleTb",
            url:"quehuo/list",
            cols: [[
                 {field: 'id', type: 'checkbox'}
                ,{field: 'drugname', title: '药名',}
                ,{field: 'changshang', title: '厂商',align:"center",width:"20%"}
                ,{field: 'beginprice', title: '进价',align:"center"}
                ,{field: 'price', title: '销售价格',align:"center"}
                ,{field: 'date', title: '有效日期',}
                ,{field: 'pihao', title: '批号',}
                ,{field: 'count', title: '库存',align:"center"}
                ,{field: 'unit', title: '单位',align:"center"}
                ,{field: 'guige', title: '规格',align:"center"}
            ]],
            page:true
        });
    })

    function search() {
        layui.use(["jquery","table"],function () {
            let $=layui.jquery;
            let drugname=$("#drugname").val();
            let where = {drugname:drugname};
            layui.table.reload("roleTb",{where});
        })
    }

    function delAll() {
        var id=new Array();
        layui.use(["jquery","layer","table"],function () {
            let $=layui.jquery;
            let table=layui.table;
            let layer=layui.layer;
            datas =table.checkStatus("roleTb").data;
            for(var i in datas) {
                id[i] = datas[i].id;
            }
            layer.confirm('确认删除选中的数据么？', {
                time: 20000,
                btn: ['确定', '取消'],
                yes(){
                    $.ajax({
                        url:"/store/deleteAllStore",
                        type:"post",
                        data:JSON.stringify(id),
                        contentType:"application/json"
                    })
                        .done(function(result){
                            layui.layer.msg(result.msg);
                            layui.table.reload("roleTb");
                        });
                }
            });
        })
    }

</script>
</body>
</html>
